<% frame_name ||= nil %>


<%= search_form_for product_list_filters_search_form_path,
  class: "filter-wrap",
  data: {
    controller: "filters dialog",
    filters_url_value: request.url
  } do |f| %>
  <%= hidden_field_tag :frame_name, frame_name if frame_name.present? %>

  <div class="d-flex flex-column flex-lg-row gap-2">
    <%= render 'spree/admin/shared/filters_search_bar', param: :multi_search %>
    <%= render "spree/admin/products/table_filter_dropdown" %>
    <%= button_tag type: 'button', class: 'btn btn-light d-flex align-items-center', data: { action: 'dialog#open' } do %>
      <%= icon "adjustments", class: "mr-1" %>
      <%= Spree.t("admin.filters") %>
    <% end %>
  </div>

  <dialog class="drawer" data-dialog-target="dialog" id="product-filters-drawer">
    <%= drawer_header(Spree.t(:filter), 'dialog') %>
    <div class="drawer-body">
    <%= f.hidden_field :status_eq, value: params.dig(:q, :status_eq) %>
    <div class="form-group">
      <%= f.label :taxons_id_in, Spree.t(:taxons) %>
      <% @categories = current_store.taxons.where(id: params.dig(:q, :taxons_id_in)).pluck(:pretty_name, :id) if params.dig(
        :q,
        :taxons_id_in,
      ) %>
      <%= tom_select_tag "q[taxons_id_in]",
      multiple: true,
      preloaded_options: @categories,
      active_option: params.dig(:q, :taxons_id_in),
      empty_option: Spree.t(:without_taxon),
      url: spree.admin_taxons_select_options_path(format: :json),
      select_data: {
        filters_target: "input",
      } %>
    </div>

    <div class="form-group">
      <%= f.label :tags_name_in, Spree.t(:tags) %>
      <%= tom_select_tag "q[tags_name_in]",
      active_option: params[:q][:tags_name_in],
      options: tags_json_array,
      multiple: true,
      value_field: :name,
      select_class: "w-100",
      select_data: {
        filters_target: "input",
      } %>
    </div>

    <%= render_admin_partials(:products_filters_partials, f: f) %>
    </div>
    <div class="drawer-footer">
      <%= drawer_discard_button('dialog') %>
      <%= render 'spree/admin/shared/filter_submit' %>
    </div>
  </dialog>

  <%= render "spree/admin/shared/filter_badge_template" %>

  <div data-filters-target="badgesContainer" class="filter-badges-container"></div>
<% end %>
